package org.ala.tiktools.rpc.tcp.config;

/**
 *
 * @author ala
 * @date 2025-04-04 13:18
 */
public class RpcTcpConfigInfo {


    /**
     *  配置信息
     *  <p> 只在启动时初始化一次
     */
    public static RpcTcpConfigInfo INSTANCE;


    /******************************************************************************************
     *  连接相关
     ******************************************************************************************/
    /**
     *  服务端端口号
     */
    protected int port;
    /**
     *  链接默认超时时间
     */
    protected int connectionTimeoutMills = 30000;
    /**
     *  当服务端处理连接较慢时，未处理的连接请求将放入队列中，默认50
     */
    protected int soBacklog = 50;


    /******************************************************************************************
     *  客户端相关
     ******************************************************************************************/
    /**
     *  客户端worker线程数
     */
    protected int clientWorkerCount = 1;
    /**
     *  服务端boss线程数
     */
    protected int serverBossCount = -1;
    /**
     *  服务端worker线程数
     */
    protected int serverWorkerCount = -1;


    /******************************************************************************************
     *  缓冲区相关
     ******************************************************************************************/
    /**
     *  写缓冲区大小，这里给64k，默认值操作系统指定：/proc/sys/net/ipv4/tcp_smem
     */
    protected int soSndbuf = 65536;
    /**
     *  读缓冲区大小，这里给32k，默认值操作系统指定：/proc/sys/net/ipv4/tcp_rmem
     */
    protected int soRcvbuf = 32768;
    /**
     *  写缓冲区的高水位，超过这个水位，channel不可写（流控）
     */
    protected int soWriteBufferHighWaterMark = 65536;
    /**
     *  写缓冲区的低水位，低于这个水位，channel将恢复（流控）
     */
    protected int soWriteBufferLowWaterMark = 32768;


    /******************************************************************************************
     *  tcp 相关
     ******************************************************************************************/
    /**
     *  tcp协议选项，当客户端超过7200s为收发消息时，tcp层会自动发送探活消息。若连续失败9次，则关闭连接
     */
    protected boolean soKeepalive = false;
    /**
     *  是否禁用Nagle算法，小数据包会立即发送。延迟小但带宽高
     */
    protected boolean tcpNoDelay = false;
    /**
     *  close()的延迟时间，确保数据完全发送
     */
    protected int soLinger = -1;


    /******************************************************************************************
     *  读写控制相关
     ******************************************************************************************/
    /**
     *  自动读取数据（是否自动触发read事件）
     */
    protected boolean autoRead = true;
    /**
     *  写入失败时自动关闭channel
     */
    protected boolean autoClose = false;


    /******************************************************************************************
     *  其他
     ******************************************************************************************/
    /**
     *  允许重复使用本地端口
     */
    protected boolean soReUseAddr = false;
    /**
     *  允许半关闭状态。一方关闭发送但仍可以发送数据
     */
    protected boolean allowHalfClosure = false;
    /**
     *  写操作的最大尝试次数
     */
    protected int writeSpinCount = 16;

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public int getConnectionTimeoutMills() {
        return connectionTimeoutMills;
    }

    public void setConnectionTimeoutMills(int connectionTimeoutMills) {
        this.connectionTimeoutMills = connectionTimeoutMills;
    }

    public int getSoBacklog() {
        return soBacklog;
    }

    public void setSoBacklog(int soBacklog) {
        this.soBacklog = soBacklog;
    }

    public int getSoSndbuf() {
        return soSndbuf;
    }

    public void setSoSndbuf(int soSndbuf) {
        this.soSndbuf = soSndbuf;
    }

    public int getSoRcvbuf() {
        return soRcvbuf;
    }

    public void setSoRcvbuf(int soRcvbuf) {
        this.soRcvbuf = soRcvbuf;
    }

    public int getSoWriteBufferHighWaterMark() {
        return soWriteBufferHighWaterMark;
    }

    public void setSoWriteBufferHighWaterMark(int soWriteBufferHighWaterMark) {
        this.soWriteBufferHighWaterMark = soWriteBufferHighWaterMark;
    }

    public int getSoWriteBufferLowWaterMark() {
        return soWriteBufferLowWaterMark;
    }

    public void setSoWriteBufferLowWaterMark(int soWriteBufferLowWaterMark) {
        this.soWriteBufferLowWaterMark = soWriteBufferLowWaterMark;
    }

    public boolean isSoKeepalive() {
        return soKeepalive;
    }

    public void setSoKeepalive(boolean soKeepalive) {
        this.soKeepalive = soKeepalive;
    }

    public boolean isTcpNoDelay() {
        return tcpNoDelay;
    }

    public void setTcpNoDelay(boolean tcpNoDelay) {
        this.tcpNoDelay = tcpNoDelay;
    }

    public int getSoLinger() {
        return soLinger;
    }

    public void setSoLinger(int soLinger) {
        this.soLinger = soLinger;
    }

    public boolean isAutoRead() {
        return autoRead;
    }

    public void setAutoRead(boolean autoRead) {
        this.autoRead = autoRead;
    }

    public boolean isAutoClose() {
        return autoClose;
    }

    public void setAutoClose(boolean autoClose) {
        this.autoClose = autoClose;
    }

    public boolean isSoReUseAddr() {
        return soReUseAddr;
    }

    public void setSoReUseAddr(boolean soReUseAddr) {
        this.soReUseAddr = soReUseAddr;
    }

    public boolean isAllowHalfClosure() {
        return allowHalfClosure;
    }

    public void setAllowHalfClosure(boolean allowHalfClosure) {
        this.allowHalfClosure = allowHalfClosure;
    }

    public int getWriteSpinCount() {
        return writeSpinCount;
    }

    public void setWriteSpinCount(int writeSpinCount) {
        this.writeSpinCount = writeSpinCount;
    }

    public int getClientWorkerCount() {
        return clientWorkerCount;
    }

    public void setClientWorkerCount(int clientWorkerCount) {
        this.clientWorkerCount = clientWorkerCount;
    }

    public int getServerBossCount() {
        return serverBossCount;
    }

    public void setServerBossCount(int serverBossCount) {
        this.serverBossCount = serverBossCount;
    }

    public int getServerWorkerCount() {
        return serverWorkerCount;
    }

    public void setServerWorkerCount(int serverWorkerCount) {
        this.serverWorkerCount = serverWorkerCount;
    }
}
